A Simple Tree Pattern Matching Algorithm for Code Generator
نویسندگان
چکیده
This p a p e r descr ibes 4 s i m p l e t r ee p a t t e r n m a t c h i n g a l g o r i t h m f o r t h e code g e n e r a t o r of compi l e r s . T h e i n t e r m e d i a t e code ( R e g i s t e r T r a n s f e r L a n g u a g e ) is m a t c h e d with t h e tree-rewri t ing ru le s of t h e i n s t r u c t i o n d e s c r i p t i o n w h i c h describe t h e t a r g e t archi tecture t o genera te t h e a s s e m b l y code. T h e hash ing f u n c t i o n is u s e d in o u r s y s t e m t o t r a n s f o r m 4 t r ee p a t t e r n m a t c h i n g p r o b l e m i n t o 4 s i m p l e n u m b e r c o m p a r i s o n . Compared with GNU C c o m p i l e r (gcc), t h e t r ee p a t t e r n m a t c h i n g t i m e c a n be reduced by 69% a n d t h e c o m p i l e r t i m e by 6%, a n d t h e space o f t h e i n s t r u c t i o n descript i o n s c a n be reduced by 4.10 t i m e s o n DLX a n d 2.14 o n SPARC. T h e s i ze of t ab le , w h i c h is n e c e s s a r y f o r code genera tor , i s qui te s m a l l in o u r m e t h o d .
منابع مشابه
Efficient Retargetable Code Generation Using Bottom-up Tree Pattern Matching
Instruction selection is the primary task in automatic code generation. This paper proposes a practical system for performing optimal instruction selection based on tree pattern matching for expression trees. A significant feature of the system is its ability to perform code generation without requiring cost analysis at code generation time. The target machine instructions are specified as attr...
متن کاملEngineering E cient Code Generators using Tree Matching and Dynamic Programming
Many code generator generators use tree pattern matching and dynamic programming. This note describes a simple program that generates matchers that are fast, compact, and easy to understand. It is simpler than common alternatives: 200{700 lines of Icon versus 3000 lines of C for Twig and 5000 for burg. Its matchers run up to 25 times faster than Twig's. They are necessarily slower than burg's B...
متن کاملOne-Pass, Optimal Tree Parsing - With Or Without Trees
This paper describes the theory behind and implementation of wburg, a code-generator generator that accepts tree grammars as input and produces a code generator that emits an optimal parse of an IR tree in just a single bottom-up pass. Furthermore, wburg eliminates the need for an explicit IR tree altogether. The grammars that wburg-generated parsers can parse are a proper subset of those that ...
متن کاملA Fast General Parser for Automatic Code Generation
The code generator in a compiler attempts to match a subject tree against a collection of tree-shaped patterns for generating instructions. Tree-pattern matching may be considered as a generalization of string parsing. We propose a new generalized LR (GLR) parser, which extends the LR parser stack with a parser cactus. GLR explores all plausible parsing steps to find the least-cost matching. GL...
متن کاملCode Selection Techniques: Pattern Matching, Tree Parsing, and Inversion of Derivors
Significant progress in the area of formal tools to support the construction of code generators in recent years has come along with a severe terminological confusion. Closely related techniques appear in different styles, further obscured by ad-hoc extensions. We try to alleviate this situation by suggesting that the code selection task should be understood as the problem of inversion of a hier...
متن کاملPattern Matches in HOL: - A New Representation and Improved Code Generation
Pattern matching is ubiquitous in functional programming and also very useful for definitions in higher-order logic. However, it is not directly supported by higher-order logic. Therefore, the parsers of theorem provers like HOL4 and Isabelle/HOL contain a pattern-compilation algorithm. Internally, decision trees based on case constants are used. For non-trivial case expressions, there is a big...
متن کامل